import module namespace common = "http://www.metaphoricalweb.com/xmlns/common" at "/xrai/common/xq/common.xq";
declare namespace atom="http://www.w3.org/2005/Atom";
declare option exist:serialize "media-type=text/xml";

let $user := session:set-current-user("admin","")
let $data := request:get-data()
let $prefix := substring-before(name($data),":")
let $app := "xrai" (: I'll be working this one into an external variable :)
let $conf := doc(concat("/db/",$app,"/common/conf/conf.xml"))
let $domain := $conf//domain[string(@id) = $app]
let $topic := $domain//topic[string(@id) = $prefix]
let $objectData := string($topic/@object-data) 
let $id :=string($data//*:Id)
let $update := xmldb:store($objectData,concat($id,'.xml'),$data)
return $data
